const globalIp = getApp().globalData.userIp
Page({

  /**
   * 页面的初始数据
   */
  data: {
    code: '',
    status: true,
    info: '',
    alreadyOrder: []
  },

  scanCode: function() {
    var that = this;
    wx.scanCode({
      onlyFromCamera: true,
      success: function(res) {
        console.log("扫码成功：" + JSON.stringify(res));
        that.setData({
          code: res.result
        })
        that.alreadyShow()
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  getInputValue:function(e) {
    this.setData({
      code: e.detail.value
    })
  },

  selectData: function(){
    this.alreadyShow();
  },
  
  alreadyShow: function(){
    var that = this;
    wx.showLoading({
      title: '数据加载中...',
    })
    wx.request({
      url: globalIp + 'home/oitm/selWhsStock',
      data: {
        openId: wx.getStorageSync('userInfo').openid,
        value: that.data.code
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function(res) {
        var data = res.data.jsonObject.data;
        if (data.length > 1) {
          var arr = [];
          var ress = [];
          for (var i in data) {
            arr[i] = [];
            for(var j in data[i]) {
              arr[i].push(data[i][j]);
            }
          }
          for (var i = 0; i < arr[0].length; ++i) {
            ress[i] = [];
            for (var j = 0; j < arr.length; ++j) {
              ress[i][j] = arr[j][i];
            }
          }
          that.setData({
            alreadyOrder: ress
          })
        } else {
          that.setData({
            status: false,
            info: data[0].title
          })
        }
      },
      complete: () => {
        wx.hideLoading()
      }
    })
  },

})